<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>{{ leftCount }}</strong></span
    >
    <ul class="filters">
      <!-- 有疑问 -->
      <li>
        <a
          :class="{ selected: selectType === 'all' }"
          @click="changeType('all')"
          href="javascript:;"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: selectType === 'active' }"
          @click="changeType('active')"
          href="javascript:;"
          >未完成</a
        >
      </li>
      <li>
        <a
          :class="{ selected: selectType === 'complete' }"
          @click="changeType('complete')"
          href="javascript:;"
          >已完成</a
        >
      </li>
    </ul>
    <button @click="del" v-show="showClear" class="clear-completed">
      清除已完成
    </button>
  </footer>
</template>

<script>
export default {
  props: ["arr"],
  data() {
    return {
      selectType: "all",
    };
  },
  methods: {
    del() {
      this.$emit("clearDone");
    },
    //? 有疑问
    changeType(type) {
      this.selectType = type;
      this.$emit("changeType", type);
    },
  },
  computed: {
    showClear() {
      return this.arr.some((item) => item.isDone);
    },
    leftCount() {
      return this.arr.filter((item) => item.isDone === false).length;
    },
  },
};
</script>
